package com.ruoyi.daily.service.impl;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.daily.domain.dto.ReceivedThisMonthDto;
import com.ruoyi.daily.domain.dto.RechargeOrWithdrawalReviewDto;
import com.ruoyi.daily.domain.dto.SettlementOfBranchHeadquartersDto;
import com.ruoyi.daily.domain.vo.RechargeOrWithdrawalReviewVo;
import com.ruoyi.daily.mapper.BranchSettlementMapper;
import com.ruoyi.daily.service.BranchSettlementService;
import com.ruoyi.hqfinance.domain.HqBillDataShow;
import com.ruoyi.hqfinance.domain.vo.HqBillDataShowVo;
import com.ruoyi.hqfinance.mapper.HqBillDataShowMapper;
import com.ruoyi.logistic.domain.NetworkJuniorBill;
import com.ruoyi.logistic.mapper.NetworkJuniorBillMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;

/**
 * @Author cmz
 * @Date 2024-06-01 14:01
 */
@Service
public class BranchSettlementServiceImpl implements BranchSettlementService {
    @Resource
    private BranchSettlementMapper branchSettlementMapper;
    
    @Resource
    private HqBillDataShowMapper hqBillDataShowMapper;
    @Resource
    private NetworkJuniorBillMapper networkJuniorBillMapper;
    
    @Override
    public R<SettlementOfBranchHeadquartersDto> settlementOfBranchHeadquarters() {
        SettlementOfBranchHeadquartersDto settlementOfBranchHeadquartersDto = branchSettlementMapper.settlementOfBranchHeadquarters();
        return R.ok(settlementOfBranchHeadquartersDto);
    }

    @Override
    public List<Map<String, Object>> billDataShow() {
        HqBillDataShowVo hqBillDataShowVo = new HqBillDataShowVo();
        hqBillDataShowVo.setCollectType(2);
        List<HqBillDataShow> hqBillDataShows = hqBillDataShowMapper.billDataShow(hqBillDataShowVo);
        List<Map<String, Object>> list = new ArrayList<>();
        for (HqBillDataShow hqBillDataShow : hqBillDataShows) {
            Map<String, Object> map = new HashMap<>();
            map.put("typeName",hqBillDataShow.getTypeName());
            map.put("income",hqBillDataShow.getIncome());
            map.put("expend",hqBillDataShow.getExpend());
            list.add(map);
        }
        return list;
    }

    @Override
    public R<List<RechargeOrWithdrawalReviewDto>> rechargeOrWithdrawalReview(RechargeOrWithdrawalReviewVo rechargeOrWithdrawalReviewVo) {
        List<RechargeOrWithdrawalReviewDto> list = branchSettlementMapper.rechargeOrWithdrawalReview(rechargeOrWithdrawalReviewVo);
        return R.ok(list);
    }

    @Override
    public R<NetworkJuniorBill> warningConfiguration(String accountCode) {
        NetworkJuniorBill networkJuniorBill = networkJuniorBillMapper.selectByAccountCode(accountCode);
        return R.ok(networkJuniorBill);
    }

    @Override
    public R saveWarningConfiguration(NetworkJuniorBill networkJuniorBill) {
        boolean update = networkJuniorBillMapper.update(networkJuniorBill);
        if (update){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    
}
